package com.logic.system.ws;

import java.util.Map;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.landseaserver.common.util.StringTools;
import com.logic.system.ws.interceptor.ReadWriteSwitchManage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 *
 * 项目名称：system-server</br>
 * 类名称：SystemControllRest</br>
 * 类描述：系统控制</br>
 * 创建人：Aaron</br>
 * 创建时间：2017年9月22日 下午1:52:16</br>
 * @version 1.0
 *
 */
@Path("/system/controll")
@Api(value = "系统控制")
public class SystemControllRest 
{
    private static final Logger LOG = LoggerFactory.getLogger(SystemControllRest.class);
    
    @POST
    @Path("/changeSqlLogSwitch")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "修改系统打印SQL日志开关")
    public Response changeSqlLogSwitch(@ApiParam(value = "param", required = true) Map<String,Object> reqMap)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            String authKey = StringTools.getString(reqMap.get("SYSTEM_AUTH_KEY"));
            if ("logic123".equals(authKey))
            {
                String switchFlag = StringTools.getString(reqMap.get("switchFlag"));
                if ("1".equals(switchFlag))
                {
                    LOG.info("changeSqlLogSwitch|开启打印SQL控制.");
                    ReadWriteSwitchManage.setSwitch(true);
                }
                else if ("0".equals(switchFlag))
                {
                    LOG.info("changeSqlLogSwitch|关闭打印SQL控制.");
                    ReadWriteSwitchManage.setSwitch(false);
                }
            }
            map.setResult(CommonResult.SUCCESS);
        }
        catch (Exception e)
        {
            LOG.info("changeSqlLogSwitch|错误.", e);
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
}
